package service

import (
	"gin-elas-student-info/model"
	"github.com/gin-gonic/gin"
	"github.com/olivere/elastic/v7"
	"math/rand"
	"net/http"
)

type StudentService struct {
	elasticClient *elastic.Client
	indexName     string
}

func CreateStudent(c *gin.Context) {
	var student model.Student
	if err := c.ShouldBind(&student); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	//// 设置ID和创建时间
	//student.ID = generateID()
	//student.CreatedAt = time.Now()
	//
	//// 保存到Elasticsearch
	//
	//_, err := .Index().
	//	Index(elasticIndexName).
	//	Id(student.ID).
	//	BodyJson(student).
	//	Do(context.Background())
	//if err != nil {
	//
	//}

}

func GetStudent(c *gin.Context) {
	//id :=
}

func generateID() string {
	const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	b := make([]byte, 16)
	for i := range b {
		b[i] = charset[rand.Intn(len(charset))]
	}
	return string(b)
}
